//
//  HomeButtonView.m
//  AmountBody
//
//  Created by smm on 2018/1/22.
//  Copyright © 2018年 RCMTM. All rights reserved.
//

#import "HomeButtonView.h"

@implementation HomeButtonView
-(instancetype)init
{
    self = [super init];
    if (self) {
        [self initSubViews];
    }
    return self;
}
-(instancetype)initWithFrame:(CGRect)frame
{
    self = [super initWithFrame:frame];
    if (self) {
        [self initSubViews];
    }
    return self;
}
/*
// Only override drawRect: if you perform custom drawing.
// An empty implementation adversely affects performance during animation.
- (void)drawRect:(CGRect)rect {
    // Drawing code
}
*/
-(void)initSubViews
{
    _bg_image = [[UIImageView alloc]init];
    [self addSubview:_bg_image];
    _signImage  = [[UIImageView alloc]init];
    [_bg_image addSubview:_signImage];
    _nameLabel = [[UILabel alloc]init];
    [_bg_image addSubview:_nameLabel];
    _valueLabel = [[UILabel alloc]init];
    [_bg_image addSubview:_valueLabel];
}
-(void)loadHomeButtonWithModel:(ClassModel *)model
{
    CGFloat jianGeW = 0;
    CGFloat jianGeH = 0;
    self.backgroundColor = [UIColor clearColor];
    [_bg_image mas_remakeConstraints:^(MASConstraintMaker *make) {
        make.edges.equalTo(self).insets(UIEdgeInsetsMake(jianGeH, jianGeW, -jianGeH, -jianGeW));
        
    }];
    [_bg_image setYuanJiaoForRadius:8.0 andMasks:YES];
    _bg_image.image = [UIImage imageNamed:model.imageUrl];
    _bg_image.userInteractionEnabled = YES;
    [self bringSubviewToFront:_bg_image];
    _nameLabel.text = model.name;
    _nameLabel.font = [UIFont systemFontOfSize:22.0];
    _nameLabel.textColor = [UIColor whiteColor];
    _nameLabel.textAlignment = NSTextAlignmentCenter;
//    [_nameLabel sizeToFit];
    [_nameLabel mas_remakeConstraints:^(MASConstraintMaker *make) {
        make.height.equalTo(@(Nomal_Label_H));
        make.left.right.equalTo(_bg_image);
        make.centerY.equalTo(_bg_image);
    }];
    CGFloat imageW = 20;
    CGFloat imageH = 20;
    [_signImage mas_remakeConstraints:^(MASConstraintMaker *make) {
        make.width.equalTo(@(imageW));
        make.height.equalTo(@(imageH));
        make.centerX.equalTo(_bg_image);
        make.top.equalTo(_nameLabel.mas_bottom).offset(10);
    }];
    _signImage.image = [UIImage imageNamed:@"@down"];
    [_valueLabel mas_remakeConstraints:^(MASConstraintMaker *make) {
        make.height.equalTo(@(Nomal_Label_H));
        make.left.right.equalTo(_bg_image);
        make.centerX.equalTo(_bg_image);
        make.bottom.equalTo(_bg_image).offset(-5);
    }];
    _valueLabel.text = model.value;
    _valueLabel.textAlignment = NSTextAlignmentCenter;
    _valueLabel.textColor = [UIColor whiteColor];
    NSDictionary *dic = @{NSFontAttributeName:[UIFont systemFontOfSize:15.0], NSKernAttributeName:@5.f};
    
    NSAttributedString *attributeStr = [[NSAttributedString alloc] initWithString:model.value attributes:dic];
    _valueLabel.attributedText = attributeStr;
}

@end
